import { Injectable } from '@nestjs/common';
import * as dayjs from 'dayjs';
@Injectable()
export class ApDeviceService {
  private antInfos = [
    {
      device_id: 'string1',
      soft_id: 'string1',
      etc_id: 'string1',
      etc_version: 'string1',
      ant_type: 'string1',
      factory_id: 'string1',
      name: 'string',
      manufacturer: 'string',
      sn: 'string',
      manufacturing_date: 'string',
      soft_version: 'string',
      model: 'string',
      device_version: 'string',
      soft_crc: 'string',
    },
    {
      device_id: 'string2',
      soft_id: 'string2',
      etc_id: 'string2',
      etc_version: 'string2',
      ant_type: 'string2',
      factory_id: 'string2',
      name: 'string',
      manufacturer: 'string',
      sn: 'string',
      manufacturing_date: 'string',
      soft_version: 'string',
      model: 'string',
      device_version: 'string',
      soft_crc: 'string',
    },
  ];

  //获取天线设备信息
  async getAntInfo() {
    return {
      code: 200,
      message: 'success',
      data: {
        ant: this.antInfos,
      },
    };
  }

  private antStatus = {
    buc_warn: 'abnormal',
    bdc_warn: 'abnormal',
    temp: 'string',
    inertial_navigate_warn: 'abnormal',
    overtemp_warn: 'abnormal',
    transmit_front_status_1: 'abnormal',
    transmit_front_status_2: 'abnormal',
    transmit_front_status_3: 'abnormal',
    transmit_front_status_4: 'abnormal',
    receive_front_status_1: 'abnormal',
    receive_front_status_2: 'abnormal',
    receive_front_status_3: 'abnormal',
    receive_front_status_4: 'abnormal',
  };

  //获取天线相控阵状态
  async getAntStatus() {
    return {
      code: 200,
      message: 'success',
    };
  }

  public simFailCount = 0;
  public simFailThreshold = 5;
  //获取SIM卡号
  async getSimId() {
    let simId = '';
    this.simFailCount++;
    if (this.simFailCount >= this.simFailThreshold) {
      simId = '88888888';
      this.simFailCount = 0;
    } else {
      simId = '';
    }
    console.log(this.simFailCount, 'simFailCount');
    return {
      data: {
        sim_id: [88888888, 88888888],
      },
      code: 200,
      message: 'success',
    };
  }

  private kpsuInfo = {
    device_type: 'string',
    device_pn: 'string',
    device_sn: 'string',
    device_version: 'string',
    soft_pn: 'string',
    soft_version: 'string',
  };
  // 获取KPSU设备信息
  async getKpsuInfo() {
    return {
      code: 200,
      message: 'success',
      data: this.kpsuInfo,
    };
  }

  private kpsuStatus = {
    fan: 'abnormal',
    module: 'abnormal',
    temp: 45,
    rs422: 'abnormal',
    power_in: 'normal',
    power_out: 'normal',
    online: 'normal',
    temperature: 'abnormal',
  };

  // 获取KPSU自检状态
  async getKpsuStatus() {
    return {
      code: 200,
      message: 'success',
      data: this.kpsuStatus,
    };
  }

  private cpInfoList = [
    {
      soft_id: 'string',
      etc_id: 'string',
      etc_version: 'string',
      name: 'string',
      manufacturer: 'string',
      soft_version: 'string',
      boot_version: 'string',
      driver_version: 'string',
    },
    {
      soft_id: 'string',
      etc_id: 'string',
      etc_version: 'string',
      name: 'string',
      manufacturer: 'string',
      soft_version: 'string',
      boot_version: 'string',
      driver_version: 'string',
    },
  ];

  // 获取cp设备信息
  async getCpInfo() {
    return {
      code: 200,
      message: 'success',
      data: {
        cp_list: this.cpInfoList,
      },
    };
  }

  private discrete = {
    disc_out0: 0,
    disc_out1: 0,
    disc_out2: 0,
    disc_out3: 0,
    disc_out4: 0,
    disc_out5: 0,
    disc_out6: 0,
    disc_out7: 0,
    disc_in0: 1,
    disc_in1: 1,
    disc_in2: 1,
    disc_in3: 0,
    disc_in4: 1,
    disc_in5: 1,
    disc_in6: 1,
    disc_in7: 1,
  };

  getDiscrete() {
    return {
      code: 200,
      message: 'success',
      data: this.discrete,
    };
  }

  private apInfo = {
    device_sn: 'string',
    device_date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    net_info: ['192.168.1.1'],
  };

  //获取ap设备信息
  async getApInfo() {
    return {
      code: 200,
      message: 'success',
      data: this.apInfo,
    };
  }
}
